
<!DOCTYPE html>
<html>
<head>
<base href="../">
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="js/layer/layer.js"></script>
<script type="text/javascript" src="js/template.js"></script>
<script type="text/javascript" src="js/base.js"></script>
<script type="text/javascript" src="js/code.js"></script>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/base.css">
</head>
<body>
	<script type="text/html" id="template1">
	<% for(var i=0;i<data.length;i++){ 
		var item=data[i];
	%>
		<tr><td><%=item.name%></td>
         <td><%=item.statusname%></td>
				<td>
				<a href="javascript:;" onclick="edit(this,<%=item.id%>)">修改</a>
				<a href="javascript:;" onclick="del(this,<%=item.id%>)">删除</a>
               <a href="javascript:;" onclick="code(this,<%=item.id%>)">二维码</a>
				</td>
		</tr>
    <%}%>
</script>
	<input type="text" class="form-control search" name="search"
		placeholder="录入查询的名称">
	<button onclick="search();">查询</button>
	<button onclick="add();">新增</button>
	<table class="table table-bordered">
		<thead>
			<tr>
				<td>名称</td>
				<td>餐位状态</td>
				<td>功能</td>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	<div class="pageinfo">
		<a href="javascript:;" page="1">上一页</a> <a href="javascript:;"
			page="2">下一页</a>
	</div>
	<script type="text/javascript">
		function add() {
			openLayer("Desk/edit.html", "新增餐位", [ "500px", "400px" ]);
		}
		function edit(target, id) {
			openLayer("Desk/edit.html?id=" + id, "修改餐位", [ "500px", "400px" ]);
		}
		function del(target, id) {

			openConfirm("确认删除？", function() {
				var self = $(target);
				ajax_get("Desk/delete", {
					id : id
				}, function(json) {
					if (json.status > 0) {
						self.parents("tr").remove();
					}
				})

			})

		}
		function code(target, id) {

			var msg = $('<div class="pan" style="margin-left:10px;"  >');
			$("body").append(msg);

			var qrcode1 = new QRCode($(".pan")[0], {

				width : 200,
				height : 200

			});
			qrcode1
						.makeCode("http://192.168.43.179/ClientHome/index.html?deskno="
							+ id);
			openCode(msg, "餐桌二维码")

		}

		function load(param) {
			ajax_get(
					"Desk/index",
					param,
					function(json) {
						var myTemplate = document.getElementById('template1').innerHTML;
						var myHtml = miniTpl(myTemplate, json.data);
						$("table tbody").empty();
						$("table tbody").append($(myHtml));
					})
		}
		function search() {
			var txt = $("[name=search]").val();
			load({
				search : txt,
				pageno : 1
			})
		}

		$(function() {

			load({})

			$(".pageinfo").on("click", "a", function() {
				var page = parseInt($(this).attr("page"));
				$(".pageinfo a:eq(0)").attr("page", page > 1 ? page - 1 : 1);
				$(".pageinfo a:eq(1)").attr("page", page + 1);
				var txt = $("[name=search]").val();
				load({
					pageno : page,
					search : txt
				})

			})

		})
	</script>

</body>
</html>